#!/usr/bin/env python
import sys
import class_set
import helper
from sets import Set

class FeedRecommendationReducer(helper.ReducerHelper):
    """
    from contentid\ttag and contentid\ttag(which is review)
    get result
    """
    res = []

    def summary(self):
        if len(self.res) == 0:
            return
        recom_result = class_set.RecomResult()
        recom_result.ppuid = '0'
        recom_result.reason_id = '104'
        recom_result.reason_desc = 'common'
        recom_result.expired_time = 1*24*60*60
        recom_result.resys_items = self.res
        print recom_result

    def processor(self, key, lst):
        clean = True
        comment = 0
        forward = 0
        like = 0
        for e in lst:
            recom_tag = class_set.RecomTagFeed('')
            recom_tag.init(e)
            if recom_tag.getType() == 'like':
                like += 1
            elif recom_tag.getType() == 'comment':
                comment += 1
            elif recom_tag.getType() == 'forward':
                forward += 1
            elif recom_tag.getType() == 'review':
                clean = False
            else:
                pass
        if not clean:
            recom_atom = class_set.RecomAtom()
            recom_atom.item_id = key
            if comment>0 or forward>0 or like>0:
                recom_atom.involved_num = (forward+comment+like)
                self.res.append(recom_atom)

            

def main():
    fr = FeedRecommendationReducer()
    fr.reducer()
    fr.summary()

if __name__ == '__main__':
    main()









